const mongoose = require('mongoose')
const { Schema, model } = mongoose
const userSchema = new Schema(
  {
    __v: { type: Number, select: false },
    // 用户名
    name: { type: String, required: true },
    // 密码
    password: { type: String, required: true, select: false },
    // 用户头像
    avatar_url: { type: String },
    // 性别
    gender: {
      type: String,
      enum: ['male', 'female'],
      default: 'male',
      required: true
    },
    // 一句话简介
    headline: { type: String },
    // 居住地
    locations: {
      type: [{ type: Schema.Types.ObjectId, ref: 'Topic' }],
      select: false
    },
    // 所在行业
    business: { type: Schema.Types.ObjectId, ref: 'Topic', select: false },
    // 职业经历
    employments: {
      type: [
        {
          company: { type: Schema.Types.ObjectId, ref: 'Topic' },
          job: { type: Schema.Types.ObjectId, ref: 'Topic' }
        }
      ],
      select: false
    },
    // 教育经历
    educations: {
      type: [
        {
          school: { type: Schema.Types.ObjectId, ref: 'Topic' },
          major: { type: Schema.Types.ObjectId, ref: 'Topic' },
          diploma: { type: Number, enum: [1, 2, 3, 4, 5] },
          entrance_year: { type: Number },
          granduation_year: { type: Number }
        }
      ],
      select: false
    },
    // 我关注的用户
    following: {
      type: [{ type: Schema.Types.ObjectId, ref: 'User' }],
      select: false
    },
    // 我关注的话题
    followingTopics: {
      type: [{ type: Schema.Types.ObjectId, ref: 'Topic' }],
      select: false
    },
    // 我关注的问题
    followingQuestions: {
      type: [{ type: Schema.Types.ObjectId, ref: 'Question' }],
      select: false
    },
    // 我赞过的答案
    likingAnswers: {
      type: [{ type: Schema.Types.ObjectId, ref: 'Answer' }],
      select: false
    },
    // 我踩过的答案
    dislikingAnswers: {
      type: [{ type: Schema.Types.ObjectId, ref: 'Answer' }],
      select: false
    },
    // 我收藏的答案
    collectingAnswers: {
      type: [{ type: Schema.Types.ObjectId, ref: 'Answer' }],
      select: false
    }
  },
  { timestamps: true }
)
module.exports = model('User', userSchema)
